<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>
    // 计算下面的题目
    // 求 [ 1, 3, 5, 2, 8, 7, 6, 9 ] 的最大值, 最小值, 和, 积, 平均值.
    // 要求分别使用循环完成.
    // var arr = [ 1, 3, 5, 2, 8, 7, 6, 9 ];
    // 怎么封装???

    /*
    var arr = [ 1, 3, 5, 2, 8, 7, 6, 9 ];

    var max = arr[ 0 ];
    for ( var i = 0; i < arr.length; i++ ) {
        if ( max < arr[ i ] ) {
            max = arr[ i ];
        }
    }
    console.log( 'max = ' + max );

    var min = arr[ 0 ];
    for ( var i = 0; i < arr.length; i++ ) {
        if ( min > arr[ i ] ) {
            min = arr[ i ];
        }
    }
    console.log( 'min =' + min );

    var sum = 0;
    for ( var i = 0; i < arr.length; i++ ) {
        sum += arr[ i ];
    }
    console.log(sum);
    */

    function each( arr, callback ) {
        for ( var i = 0; i < arr.length; i++ ) {
            callback( arr[ i ], i );
        }
    }
    var arr = [ 1, 3, 5, 2, 8, 7, 6, 9 ];

    var max = arr[ 0 ];
    each( arr, function ( v, i ) {
        if ( max < v ) {
            max = v;
        }
    });
    console.log(max);


</script>
</html>